package com.gm.englishdemo3.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.gm.englishdemo3.R;
import com.gm.englishdemo3.bean.HomeWorkBean;
import com.gm.englishdemo3.utils.Base64Util;

import java.util.ArrayList;
import java.util.List;

public class HomeWorkAdapter extends RecyclerView.Adapter<HomeWorkAdapter.InnerHolder> {

    static List<HomeWorkBean> data=new ArrayList<>();

    public void setData(List<HomeWorkBean> it){
        data.clear();
        data.addAll(it);
        notifyDataSetChanged();
    }

    public static void insertData(HomeWorkBean bean){
        data.add(0,bean);
        HomeWorkBean homeWork=data.get(0);
    }

    @NonNull
    @Override
    public InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new InnerHolder(
                LayoutInflater.from(parent.getContext()).inflate(R.layout.item_content,parent,false)
        );
    }

    @Override
    public void onBindViewHolder(@NonNull InnerHolder holder, int position) {
        HomeWorkBean homeWork=data.get(position);
        ImageView photo=holder.itemView.findViewById(R.id.lv_photo);
        TextView projectId=holder.itemView.findViewById(R.id.lv_projectID);
        TextView studentId=holder.itemView.findViewById(R.id.lv_studentID);
        TextView title=holder.itemView.findViewById(R.id.lv_title);
        TextView description=holder.itemView.findViewById(R.id.lv_description);
        TextView secondName=holder.itemView.findViewById(R.id.lv_secondName);
        TextView firstName=holder.itemView.findViewById(R.id.lv_firstName);
        TextView year=holder.itemView.findViewById(R.id.lv_year);
        projectId.setText("您的项目ID:"+homeWork.getProjectId()+"");
        studentId.setText("您的学号:"+homeWork.getStudentId()+"");
        title.setText("您的标题:"+homeWork.getTitle()+"");
        photo.setImageBitmap(Base64Util.getBitMap(homeWork.getPhoto()));
        description.setText("您的描述:"+homeWork.getDescription()+"");
        secondName.setText("您的性:"+homeWork.getSecondName()+"");
        firstName.setText("您的名:"+homeWork.getFirstName()+"");
        year.setText("您的入学年龄:"+homeWork.getYear()+"");
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class InnerHolder extends RecyclerView.ViewHolder {
        public InnerHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
